//
//  ThreeArtTableViewController.m
//  开心一刻
//
//  Created by lanou on 16/4/7.
//  Copyright © 2016年 刘洋. All rights reserved.
//

#import "ThreeArtTableViewController.h"
#import "Requestmanager.h"
#import "HZWPictureModel.h"
#import "HZWPictureTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface ThreeArtTableViewController ()
@property(nonatomic,strong)NSArray * modelArray;

@end

@implementation ThreeArtTableViewController
-(void)craetPicture{
    
    Requestmanager * manage = [[Requestmanager alloc]init];
    [manage requestWithUrl:@"http://ic.snssdk.com/neihan/stream/mix/v1/?content_type=-102&iid=3598776185&os_version=9.0.2&os_api=18&app_name=joke_essay&channel=App%20Store&device_platform=iphone&idfa=073F20C4-A8E1-4FF1-A108-FD2C3D1E2A2A&vid=CEE298FE-2CE3-4B46-9B8F-300B8C1C513C&openudid=ae1e4625636f7cf8f2a3ce5fbacb1606881639ee&device_type=iPhone%206&version_code=5.0.1&ac=WIFI&screen_width=750&device_id=7084213935&aid=7&city=%E4%B8%8A%E6%B5%B7%E5%B8%82&content_type=-102&count=30&essence=1&latitude=31.13009630401832&longitude=121.2839946133187&message_cursor=0&min_time=1459925547&mpic=1"
        requesType:requestTypeGET parDic:nil finish:^(NSData *data) {
    NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSLog(@"%@",dic);
    self.modelArray = [HZWPictureModel creatPictureModel:dic];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self.tableView reloadData];
                    });
            
                } error:^(NSError *error) {
                    NSLog(@"请求失败");
                }];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self craetPicture];
    
    [self.tableView registerClass:[HZWPictureTableViewCell class] forCellReuseIdentifier:@"three"];
    
    self.tableView.rowHeight = 350;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSLog(@"%+++++ld",[self.modelArray[1]count]);

    return [self.modelArray[1]count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HZWPictureTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"three" forIndexPath:indexPath];
    
    HZWPictureModel * model = _modelArray[1][indexPath.row];
    cell.contentLabel.text = model.content;
    [cell.aoturImage sd_setImageWithURL:[NSURL URLWithString:model.avatar_url] completed:nil];
    cell.aoturName.text = model.name;
    cell.style.text = model.category_name;
    
    

  
    return cell;
}

//-(CGFloat)ta
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
